/**
 * 对每个动作的种类进行计算
 */
function classifyByNavId(data: FormData[][]): { [key: number]: FormData[] } {
  const result: { [key: number]: FormData[] } = {};

  data.forEach(subArray => {
    subArray.forEach(item => {
      if (result[item.exerciseAreaId]) {
        result[item.exerciseAreaId].push(item);
      } else {
        result[item.exerciseAreaId] = [item];
      }
    });
  });

  return result;
}

/**
 * 对上面的数据进行整理
 */
function classifyNum(navName: NavItem[], cateArray: { [key: number]: FormData[] }) {
  return navName.map(item => {
    const matchedItems = cateArray[item.id];
    return {
      name: item.name,
      num: matchedItems ? matchedItems.length : 0
    };
  });
}

module.exports = {
  classifyByNavId,
  classifyNum
}